//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_getslope.sqf"
#include "x_setup.sqf"

// from warfare
// Returns an average slope value of terrain within passed radius.
// a little bit modified. no need to create a "global" logic, local is enough, etc
// parameters: position, radius
// example: _slope = [the_position, the_radius] call FUNC(GetSlope);

// TYRGHEN - I went for a solution based on ATLtoASL.. we'll see

//private ["_position", "_radius", "_centerHeight", "_height", "_direction", "_count"];
// PARAMS_2(_position,_radius);
// GVAR(SlopeObject) setPos _position;
// _centerHeight = getPosASL GVAR(SlopeObject) select 2;
// _height = 0;_direction = 0;
// for "_count" from 0 to 7 do {
	// GVAR(SlopeObject) setPos [(_position select 0) + ((sin _direction) * _radius), (_position select 1) + ((cos _direction) * _radius), 0];
	// _direction = _direction + 45;
	// _height = _height + abs (_centerHeight - (getPosASL GVAR(SlopeObject) select 2));
// };
// _height / 8

private ["_slope","_pos","_dist","_height"];

__TRACE_1("_this","_this")
_pos = _this;
_dist = 5;
_slope = 0;
if (count _this == 2) then {
	_pos = _this select 0;
	_dist = _this select 1;
};
_height = (ATLToASL _pos) select 2;
_slope = _slope + abs(((ATLToASL [(_pos select 0) - _dist, _pos select 1, 0]) select 2) - _height);
_slope = _slope + abs(((ATLToASL [(_pos select 0) + _dist, _pos select 1, 0]) select 2) - _height);
_slope = _slope + abs(((ATLToASL [_pos select 0, (_pos select 1) - _dist, 0]) select 2) - _height);
_slope = _slope + abs(((ATLToASL [_pos select 0, (_pos select 1) + _dist, 0]) select 2) - _height);
_slope = _slope / 8;
__TRACE_1("","_slope")
_slope